package com.cloud.api.config;

/**
 * @author 杨斌
 * 2024-07-10/7/2024
 */



import com.cloud.api.myenum.ReleaseTimeEnum;

import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;

public class TimeLabelUtils {

    public static ReleaseTimeEnum getTimeLabel(LocalDateTime createTime) {
        LocalDateTime now = LocalDateTime.now();
        long minutesDifference = ChronoUnit.MINUTES.between(createTime, now);

        if (minutesDifference <= 10) {
            return ReleaseTimeEnum.NOW;
        } else if (minutesDifference <= 2 * 60) {
            return ReleaseTimeEnum.TWO_HOURS_AGO;
        } else if (minutesDifference <= 24 * 60) {
            return ReleaseTimeEnum.LATELY;
        } else {
            // Beyond 24 hours, return a custom enum with formatted date
            String formattedDate = createTime.toLocalDate().toString();
            ReleaseTimeEnum.RELEASE_DATE.setDesc(formattedDate);
            return ReleaseTimeEnum.RELEASE_DATE;
        }
    }
}

